const redis = require('redis');

let client = null;

exports.connect = (config) => {
    client = redis.createClient({
        host: config.host,
        port: config.port,
        db: config.db
    });
    console.log('Connected to cityRedis');
    client.on('error', (err) => {
        console.log('Error connecting to redis', err);
    })
}

// 存储资源
exports.setResource = (key, resourcesInfo,callback) => {
    if (!client) {
        console.log('Redis client not connected');
        return;
    }
    client.HMSET(key, resourcesInfo, (err, reply) => {
        if (err) {
            callback(false);
        } else {
            callback(true);
        }
    })
    client.HGETALL(key, (err, obj) => {
        console.log(obj);
    })
}